package mongo.db.clients.firsts;

import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;

public class ReadKey {

	public static void main(String[] args) {

		List<ServerAddress> seeds = new ArrayList<ServerAddress>();

		try {
			seeds.add(new ServerAddress("202.191.136.234", 27017));
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}

		MongoClient client = new MongoClient(seeds);

		DB db = client.getDB("db_top_conversations");
		DBCollection collection = db.getCollection("db_test");
		
		System.out.println(collection.count());
		
		for ( DBObject obj : collection.find() ) {
			System.out.println(obj);
			DBObject id = (DBObject) obj.get("_id");
			
			System.out.println("srcadr : " + obj.get("_id.srcadr"));
			System.out.println("id : " + id.get("srcadr"));
			
			String ukey = obj.get("_id.srcadr") + "-" + obj.get("_id.dstadr");
			System.out.println(ukey);
			obj.put("ukey", ukey);
			
			System.out.println(obj);
			
		}
	}

}
